<template>
	<div class="bg  weui-panel">
		<div>
			<span class="sp">基本信息</span>
		</div>
		<div class="weui-panel__bd weui-cells" style="margin-top: 0rem;">
			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">姓名</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">{{userInfo.nickname}}</div>
			</a>

			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">电话</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">{{userInfo.telePhone}}</div>
			</a>
			<a class="weui-cell weui-cell_access" @click="showAddressFlag = true">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">邮寄地址</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">{{userInfo.address}}</div>
			</a>

			<a class="weui-cell weui-cell_access" @click="showEmailFlag = true">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">邮箱</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<span>{{userInfo.email}}</span>
				</div>
			</a>
		</div>
		<div>
			<span class="sp">会员等级信息</span>
		</div>
		<div class="weui-panel__bd weui-cells">
			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">会员等级</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<span>{{memberInfo.memberTypeName}}</span>
				</div>
			</a>
			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">当前等级获取时间</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<span>{{memberInfo.memberGetTime}}</span>
				</div>
			</a>
			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">总积分</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<span>{{memberInfo.jfTotal}}</span>
				</div>
			</a>
			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">当前剩余积分</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<span>{{memberInfo.jfCurrent}}</span>
				</div>
			</a>
			<a class="weui-cell ">
				<div class="weui-cell__bd df">
					<span class="demo_badge_title ">已使用积分</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<span>{{memberInfo.jfUsed}}</span>
				</div>
			</a>

		</div>

		<div>
			<button class="btn" @click="goBack">返回</button>
		</div>

		<!-- 弹框填写 -->
		<div class="dialogMain" v-if="showAddressFlag">
			<div class="bodymain">
				<div class="weui-cell__bd df">
					<span style="margin: 3px;display: inline-block;width: 100%;">邮寄地址</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<textarea class="weui-textarea" rows="5" style="height: 3.125rem;" placeholder="请输入地址"  type="text" v-model="userInfo.address" ></textarea>
				</div>
				<div class="weui-cell__ft">
					<a @click="saveUserInfo" style="width: 40%;display: inline-block;" class="weui-btn weui-btn_cell-primary">保存</a>
					<a @click="showAddressFlag = !showAddressFlag" style="display: inline-block;" class="weui-btn weui-btn_cell-primary">返回</a>
				</div>
			</div>
		</div>
		<div class="dialogMain" v-if="showEmailFlag">
			<div class="bodymain">
				<div class="weui-cell__bd df">
					<span style="margin: 3px;display: inline-block;width: 100%;">邮箱</span>
				</div>
				<div class="weui-cell__ft weui-cells__tips">
					<input  placeholder="请输入邮箱" class="weui-input" v-model="userInfo.email" type="text" />
				</div>
				<div class="weui-cell__ft">
					<a @click="saveUserInfo" style="width: 40%;display: inline-block;" class="weui-btn weui-btn_cell-primary">保存</a>
					<a @click="showEmailFlag = !showEmailFlag" style="display: inline-block;" class="weui-btn weui-btn_cell-primary">返回</a>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		getToken,
	} from '@/utils/auth'
	import apis from '@/utils/apis.js'
	import {showMsg} from '@/apis/common/common.js'
	import wxConst from '@/utils/wxContants.js'
	import {
		getUserInfo,saveUserInfo
	} from '@/apis/wx/weixinJs.js'
	import constant from '@/utils/constant'
	export default {

		data() {
			return {
				showAddressFlag:false,//显示地址填写
				showEmailFlag:false,//显示邮箱填写
				account: "", //用户账号
				userInfo: {}, //信息
				memberInfo: {}, //会员信息
			}
		},
		created() {
			let token = localStorage.getItem(constant.WX_TOKEN);
			this.account = JSON.parse(localStorage.getItem(token)).userInfo.wxUser.wxAccount
			this.getUserInfo(this.account);
		},
		methods: {
			saveUserInfo(){
				this.showAddressFlag=false,
				this.showEmailFlag=false,
				saveUserInfo(apis.saveUserInfo,this.userInfo).then(res=>{
					if (res.resultCode == constant.SUCCESS) {
						showMsg(this,"修改成功",null,"success")
					} else {
						showMsg(this,"修改失敗")
					}	
				})
			},	
			getUserInfo() {
				this.$showLoading({showLoadingToastFlag:true})
				getUserInfo(apis.getUserInfo, {
					"account": this.account
				}).then(res => {
					if (res.resultCode == constant.SUCCESS && res.data) {
						this.userInfo = res.data["wxUser"];
						this.memberInfo = res.data["wxUserMember"];
						this.memberInfo["memberTypeName"] = this.getMemberTypeName(this.memberInfo.memberCurLevel);
					}
					this.$hideLoading();

				}).catch(err =>{
					this.$hideLoading();
				})
			},
			goBack() {
				this.$router.go(-1);
			},
			getMemberTypeName(code) {
				let name = "";
				for (var i in wxConst.memberType) {
					if (wxConst.memberType[i].code == code) {
						name = wxConst.memberType[i].name;
						break;
					}
				}
				return name;
			},
		}
	}
</script>

<style scoped="scoped">
	@import "../../assets/css/returnBtn.css";
	
	.df {
		display: flex;
	}

	.sp {
		font-size: 14px;
		display: flex;
		/* width: 20%; */
		/* color: brown; */
		margin: 3px;
		background-color: beige;
	}

</style>
